package com.jame.basics.thread.Issue;

/**
 * @author : Jame
 * @date : 2021-01-10 21:05
 *
 **/
public class Test1 {

    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        new Thread(phone::sendMessage).start();
        /**
         * 加不加休眠结果一致,因为先创建线程去发短信
         * 而使用发短信因为有synchronized会锁住phone对象
         * 打电话方法会等待发短信完成释放锁后才能执行
         */
        //TimeUnit.SECONDS.sleep(1);
        new Thread(phone::call).start();
    }

}
class Phone{
    public synchronized void sendMessage(){
        System.out.println("发短信");
    }
    public synchronized void call(){
        System.out.println("打电话");
    }

}
